package com.villaday.idf.custom;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.villaday.idf.R;
import com.villaday.idf.adapter2.PopuShouYiChaKanAdapter;
import com.villaday.idf.base.BaseDialog;
import com.villaday.idf.model2.Global_configurations;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 加载中对话框
 */
public class IncomeIntroduceDialog extends BaseDialog implements View.OnClickListener {

    Unbinder unbinder;
    @BindView(R.id.rv)
    RecyclerView recyclerView;
    @BindView(R.id.tv_know)
    TextView tvBtn;

    private Global_configurations.BodyEntity beanEntity;
    private Gson gson = new GsonBuilder().create();

    public static IncomeIntroduceDialog newInstance(String str) {
        IncomeIntroduceDialog dialog = new IncomeIntroduceDialog();
        Bundle bundle = new Bundle();
        bundle.putString("str", str);
        dialog.setArguments(bundle);
        return dialog;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //取消标题显示
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        Window window = getDialog().getWindow();
        View view = inflater.inflate(R.layout.popu_vip_chakanshouyi2,
                ((ViewGroup) window.findViewById(android.R.id.content)), false);
        unbinder = ButterKnife.bind(this, view);
        //必须设置，否则不能全屏
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        //宽度撑满
        this.setCancelable(false);
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        window.setGravity(Gravity.BOTTOM);
        //进入退出动画
//        window.setWindowAnimations(R.style.animTranslateBottom);

        beanEntity = gson.fromJson(getArguments().getString("str"), Global_configurations.BodyEntity.class);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        PopuShouYiChaKanAdapter popuShouYiChaKanAdapter = new PopuShouYiChaKanAdapter(getActivity());
        recyclerView.setAdapter(popuShouYiChaKanAdapter);
        popuShouYiChaKanAdapter.setData(beanEntity.getIncomeDescriptions());
        tvBtn.setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_know:{
                dismiss();
            }
        }
    }
}
